<template>
  <div>
    <div style="padding: 10px 18px 0 18px">
      <div>说明：如果用户提交的信息已经存在于教师列表中，系统将自动通过审批。提交不存在的教师信息需要管理员人工审核。</div>
      <div>自动审核的标准：姓名和工号与已有的数据成功匹配。</div>
    </div>
    <BasicTable @register="registerTable" @fetch-success="onFetchSuccess">
      <template #toolbar>

      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
               label:'审批',
              icon: 'clarity:note-edit-line',
              onClick: handleEdit.bind(null, record),
            },
            {
             label:'驳回',
              icon: 'ant-design:delete-outlined',
              color: 'error',
              popConfirm: {
                title: '是否驳回认证？',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
    <Modal @register="registerModal" @success="handleSuccess" @handleReload="handleReload"/>
  </div>
</template>
<script lang="ts">
import {defineComponent, nextTick} from 'vue';
import {BasicTable, TableAction, useTable} from '/@/components/Table';
import {TeacherLogDel, TeacherLogList, TeacherLogPass} from '/@/api/teacher/teacher';
import {useModal} from '/@/components/Modal';
import Modal from './Modal.vue';

import {columns, searchFormSchema} from './schema.data';
import {usePermission} from '/@/hooks/web/usePermission';
import {message} from "ant-design-vue";

export default defineComponent({
  name: 'TeacherManagement',
  components: {BasicTable, Modal, TableAction},
  setup() {
    const {hasPermission} = usePermission();
    const [registerModal, {openModal}] = useModal();
    const [registerTable, {reload, expandAll}] = useTable({
      title: '教师认证审批',
      api: TeacherLogList,
      columns,
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchema,
      },
      isTreeTable: true,
      pagination: false,
      striped: false,
      useSearchForm: true,
      showTableSetting: true,
      bordered: true,
      showIndexColumn: false,
      canResize: false,
      actionColumn: {
        title: '操作',
        dataIndex: 'action',
        slots: {customRender: 'action'},
        fixed: undefined,
        ifShow: true,
      },
    });

    function handleCreate() {
      openModal(true, {
        isUpdate: false,
      });
    }

    function handleEdit(record: Recordable) {
      console.log('record', record)
      openModal(true, {
        record
      })
    }

    function handleDelete(record: Recordable) {
      TeacherLogDel({id: record.id}).then(() => {
        message.success("删除成功")
        reload();
      })
    }

    function handleReload() {
      reload();
    }

    function handleSuccess() {
      reload();
    }

    function onFetchSuccess() {
      nextTick(expandAll);
    }

    return {
      handleReload,
      registerTable,
      registerModal,
      handleCreate,
      handleEdit,
      handleDelete,
      TeacherLogPass,
      handleSuccess,
      hasPermission,
      onFetchSuccess,
    };
  },
});
</script>
